// see --> http://jsfromhell.com/classes/preloader

Preloader = function(){
    var o = this;
    o.img = [];    o.r = []; o.g = [];
    o.n = {}; o.total = o.loaded = 0;
};
Preloader.prototype.add = function(i, g){
    var o = this, n = (o.g[o.total] = [g || "general"])[0];
    (g = o.n)[n] >= 0 ? ++g[n] : g[n] = 1;
    o.img[o.total++] = i;
};
Preloader.prototype.load = function(){
    var o = this, p = o.img, l = p.length, a, g = o.g;
    while(l--){
        (g[l][1] = a = new Image()).src = p[a.i = l];
        a.onload = function(){
            if(o.r[this.i]) return;
            !--o.n[g[this.i][(o.r[this.i] = 1) - 1]] && o.onGroupComplete && o.onGroupComplete(g[this.i][0]);
            o.onImageComplete && o.onImageComplete(this);
            (++o.loaded == o.total) && o.onComplete && o.onComplete();
        };
        (a.fileSize !== undefined ? a.fileSize > -1 : a.width) && a.onload();
        a.onerror = function(){
            o.onImageError && o.onImageError(this);
        }
    }
};
Preloader.prototype.getImagesByGroup = function(n){
    var g = this.g, i = [], p = 0, n = n || "general";
    for(var j = g.length; j; g[--j][0] == n && (i[p++] = g[j][1]));
    return i;
};